package COUNTLINE;

import java.io.File;
import java.io.FileInputStream;
public class Main {

    public static void main(String[] args) {
        //FileRW.write("", "", false);
        String path=new File("").getAbsolutePath();
        System.out.println(path);
        System.out.println("Line Count:"+(count(new File(path+"\\src"))-41));
    }
    static int count(File dir) {
        System.out.println("Counting:"+dir.getPath()+" ...");
        int count=0;
        int elec=dir.listFiles().length;
        File[] lf=dir.listFiles();
        for(int i=0;i<elec;i++) {
            if(dir.listFiles()[i].isFile()) {
                String temp=read(lf[i].getAbsolutePath());
                count+=temp.split("\n").length;
                System.out.println("     "+lf[i].getAbsolutePath()+" "+temp.split("\n").length);
            }else if(lf[i].isDirectory()) {
                count+=count(lf[i]);
            }
        }
        return count;
    }
    public static String read(String s){
        File f=new File(s);
        try {
            FileInputStream fis=new FileInputStream(f);
            byte[] data=new byte[(int)f.length()];
            fis.read(data);
            fis.close();
            return new String(new String(data));
        } catch (Exception e) {
        }
        return "";
    }
}